package algotithm.leetcode.array.test1213;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author 25068
 * @Date 2021/5/13 22:55
 * @Title 1213. 三个有序数组的交集
 */
public class Solution {

    public static void main(String[] args) {
        int[] arr1 = {1,2,3,4,5};
        int[] arr2 = {1,2,5,7,9};
        int[] arr3 = {1,3,4,5,8};
        Solution solution = new Solution();
        List<Integer> integers = solution.arraysIntersection(arr1, arr2, arr3);
        System.out.println(integers);
    }

    public List<Integer> arraysIntersection(int[] arr1, int[] arr2, int[] arr3) {
        List<Integer> list = new ArrayList<>();
        Set<Integer> set1 = new HashSet<>();
        Set<Integer> set2 = new HashSet<>();
        for(int i:arr1) {
            set1.add(i);
        }
        for(int i:arr2) {
            set2.add(i);
        }
        for(int i:arr3){
            if(set1.contains(i) && set2.contains(i)) {
                list.add(i);
            }
        }
        return list;
    }
}

